/*
 * Copyright (c) 2018. QDU 2015 Java1 Team CompilationError
 */
function confirmDeleteBatch() {
	showConfirmPopup("Confirm", "Are you sure to delete the selected permission groups?",
		deleteSelected
	);
}

function confirmDelete(groupId){
	showConfirmPopup("Confirm", "Are you sure to delete the selected permission group?",
		function () {
			$.ajax({
				url: "delete_permission_group",
				data: {
					ids: [groupId]
				},
				type: "post",
				dataType: "json",
				// jsonp: true,
				success: function (data) {
					if(data.status=="ok"){
						location.reload();
					} else {
						showMessagePopup("Error", "Unable to delete permission group. There could be users in this group.");
					}
				},

				error: function(jqHXR, textStatus, error){
					console.log(error);
				}
			});
		}
	);
}

function deleteSelected(){
	var ids = [];

	var rows = table.rows('.selected').data();

	rows.each(function (val) {
		ids.push(val[0]);
	});

	$.ajax({
		url: "delete_permission_group",
		data: {
			ids: ids
		},
		type: "post",
		dataType: "json",
		// jsonp: true,
		success: function (data) {
			if(data.status=="ok"){
				location.reload();
			} else {
				showMessagePopup("Error", "Unable to delete permission groups. There could be users in these groups.");
			}
		},

		error: function(jqHXR, textStatus, error){
			console.log(error);
		}
	});
}